package com.mzj.thread;

import org.apache.log4j.Logger;
import org.apache.solr.client.solrj.SolrClient;

import com.mzj.solr.MSolrClient;
import com.mzj.solr.SolrMove;

public class SolrMoveThread implements Runnable {
	
	private static final Logger LOG = Logger.getLogger(SolrMove.class);  
	
	private Integer keyNum = null;
	
	private String index;
	
	private Long total = 0L;
	
	public SolrMoveThread() {
		super();
	}
	
	public SolrMoveThread(String index, Integer keyNum, Long total) {
		this.keyNum = keyNum;
		this.index = index;
		this.total = total;
	}

	public void run() {
		int start = keyNum*10000;
		SolrClient client = MSolrClient.getClient(index);
		SolrClient cloudClient = MSolrClient.getCloudClient();
		do {
			try {
				LOG.info("--------------total:"+total);
				LOG.info("Start move data : " + start);
				SolrMove.move(client, cloudClient, index, start);
				start = start+100000;
				if(start>1000000 && start <2000000) {
					Thread.sleep(1000);
				}else if(start>2000000 && start <3000000) {
					Thread.sleep(2000);
				}else if(start>3000000 && start <4000000) {
					Thread.sleep(3000);
				}else if(start>4000000 && start <5000000) {
					Thread.sleep(4000);
				}else {
					Thread.sleep(5000);
				}
				LOG.info("End move data : " + start);
			} catch (Exception e) {
				LOG.error(e.getMessage(),e);
				break;
			}
			LOG.info("----------------total : " + total+",start"+start);
		}while(start<=total);
		try {
			LOG.info("=============================="+keyNum+" End========================");
			client.close();
			cloudClient.close();
		} catch (Exception e) {
			LOG.error(e.getMessage(),e);
		}
	}

	public Integer getKeyNum() {
		return keyNum;
	}

	public void setKeyNum(Integer keyNum) {
		this.keyNum = keyNum;
	}

	public String getIndex() {
		return index;
	}

	public void setIndex(String index) {
		this.index = index;
	}

	public Long getTotal() {
		return total;
	}

	public void setTotal(Long total) {
		this.total = total;
	}

	
}
